<?php
class Admin{
    public static function isLogin(){
        global $auth;
        if($auth){
            return HttpData::result('json', 200, "success", true);
        }else{
            return HttpData::result('json', 401, "unauthorized", false);
        }
    }

    public static function Login(){
        global $auth,$un,$pw;
        if($auth){
            return HttpData::result('json', 200, "success", true);
        }else{
            $name = Request::post('name');
            $password = Request::post('password');
            if($name == $un && hash('sha256', $password) == $pw){
                $auth = true;
                Request::setSession('user_pw', hash('sha256', $pw)); // set session
                Request::setSession('user_fingerprint', Authentication::getBrowserFingerprint()); // set session
                return HttpData::result('json', 200, "success", true);
            }else{
                return HttpData::result('json', 401, "unauthorized", false);
            }
        }
    }
}